import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const SET_PROGRESS = 'SET_PROGRESS'

const state = Object.assign({
  initialize: false,
  token: '',
  progress: 100,
  rem: 1
})

const getters = {
  initialize: state => state.initialize,
  token: state => state.token,
  progress: state => state.progress,
  rem: state => state.rem
}

const actions = {
  initialize ({commit}, payload) {
    commit('INITIALIZE', payload)
  },
  setProgress ({commit}, progress) {
    commit(SET_PROGRESS, progress)
  }
}

const mutations = {
  'INITIALIZE' (state) {
    state.initialize = true
  },
  'set_token' (state, payload) {
    state.token = payload.token
  },
  [SET_PROGRESS] (state, payload) {
    state.progress = payload
  },
  setRem: (state, value) => {
    state.rem = value
  }
}

Vue.use(Vuex)

export default new Vuex.Store({
  strict: false,
  modules: [{
    state,
    getters,
    actions,
    mutations
  }]
})
